package com.fu.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author 付大大
 * @description
 * @create 2021-01-24 11:35
 */
@WebServlet("/servletDemo02")
public class ServletDemo02 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String connection = req.getHeader("connection");
        System.out.println(connection);
        System.out.println("-------------------------------------------");


        Enumeration<String> headers = req.getHeaders("accept-encoding");
        while (headers.hasMoreElements()) {
            String value = headers.nextElement();
            System.out.println(value);
        }
        System.out.println("-------------------------------------------");


        Enumeration<String> headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String name = headerNames.nextElement();
            String value = req.getHeader(name);
            System.out.println(name + "," + value);
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
